package ${content.items.serviceImpl.packageName};
<#assign assign_ClassName = content.items.serviceImpl.className>
<#assign assign_EntityName = content.items.entity.className>
<#assign assign_daoName = content.items.dao.camelName>
<#assign tableName = content.content.tableName>
<#assign tableRemark = content.content.remark>
<#assign camelName = content.content.camelName>
import com.yixiekeji.core.ConstantsEJS;
import com.yixiekeji.core.FeignUtil.FeignUtil;
import com.yixiekeji.core.PagerInfo;
import com.yixiekeji.core.ServiceResult;
import com.yixiekeji.core.exception.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import ${content.items.service.packageName}.${content.items.service.className};
import ${content.items.entity.packageName}.${content.items.entity.className};
import ${content.items.model.packageName}.${content.items.model.className};

/**
 * ${tableName}${tableRemark}接口的默认实现
 * @author liuyandeng
 */
@RestController
public class ${assign_ClassName} implements ${content.items.service.className} {
	private static Logger log = LoggerFactory.getLogger(${assign_ClassName}.class);
	@Resource(name = "${content.items.model.className?uncap_first}")
	private ${content.items.model.className} model;

	//查询${tableRemark}列表
	@Override
	public ServiceResult<List<${assign_EntityName}>> get${assign_EntityName}List(@RequestBody FeignUtil feignUtil) {
		Map<String, String> queryMap = feignUtil.getQueryMap();
		PagerInfo pager = feignUtil.getPager();
		ServiceResult<List<${assign_EntityName}>> serviceResult = new ServiceResult();
		serviceResult.setPager(pager);
        try {
			queryMap.put("q_isParent", "0");
			Integer start = 0, size = 0;
			if (pager != null) {
				pager.setRowsCount(model.get${assign_EntityName}Count(queryMap));
				start = pager.getStart();
				size = pager.getPageSize();
			}
			List<${assign_EntityName}> list = model.get${assign_EntityName}List(queryMap, start, size);
			serviceResult.setResult(list);
        } catch (BusinessException e) {
			serviceResult.setSuccess(false);
			serviceResult.setMessage(e.getMessage());
			log.error("[${content.items.service.className}][get${assign_EntityName}List]根据条件取得${tableName}表时出现异常：" + e.getMessage());
        } catch (Exception e) {
			serviceResult.setError(ConstantsEJS.SERVICE_RESULT_CODE_SYSERROR, "服务异常，请联系系统管理员。");
			log.error("[${content.items.service.className}][get${assign_EntityName}List] param1:" + queryMap.toString() + " &param2:" + pager.toString());
			log.error("[${content.items.service.className}][get${assign_EntityName}List]根据条件取得${tableName}表时出现未知异常：", e);
        }
        return serviceResult;
    }
<#if content.content.primaryField??>
	<#assign assign_idFieldType = content.content.primaryField[0].fieldType>
	<#assign assign_idFieldName = content.content.primaryField[0].fieldName>

	//获取${tableRemark}详情
	@Override
	public ServiceResult<${assign_EntityName}> get${assign_EntityName}ById(@RequestParam("id") ${assign_idFieldType} ${assign_idFieldName}) {
		ServiceResult<${assign_EntityName}> serviceResult = new ServiceResult<${assign_EntityName}>();
        try {
            serviceResult.setResult(model.get${assign_EntityName}ById(id));
		} catch (BusinessException e) {
			serviceResult.setSuccess(false);
			serviceResult.setMessage(e.getMessage());
			log.error("[${content.items.service.className}][get${assign_EntityName}ById]查询${tableName}表时出现异常：" + e.getMessage());
        } catch (Exception e) {
			serviceResult.setError(ConstantsEJS.SERVICE_RESULT_CODE_SYSERROR, "服务异常，请联系系统管理员。");
			log.error("[${content.items.service.className}][get${assign_EntityName}ById]查询${tableName}表时出现异常：", e);
		}
        return serviceResult;
    }

	//保存${tableRemark}
	@Override
	public ServiceResult<Integer> save${assign_EntityName}(@RequestBody ${assign_EntityName} ${camelName}) {
		ServiceResult<Integer> serviceResult = new ServiceResult();
        try {
            serviceResult.setResult(model.save${assign_EntityName}(${camelName}));
		} catch (BusinessException e) {
			serviceResult.setSuccess(false);
			serviceResult.setMessage(e.getMessage());
			log.error("[${content.items.service.className}][save${assign_EntityName}]保存${tableName}表时出现异常：" + e.getMessage());
        } catch (Exception e) {
			serviceResult.setError(ConstantsEJS.SERVICE_RESULT_CODE_SYSERROR, "服务异常，请联系系统管理员。");
			log.error("[${content.items.service.className}][save${assign_EntityName}]保存${tableName}表时出现异常：", e);
        }
			return serviceResult;
    }

	//更新${tableRemark}
	@Override
	public ServiceResult<Integer> update${assign_EntityName}(@RequestBody ${assign_EntityName} ${camelName}) {
		ServiceResult<Integer> serviceResult = new ServiceResult();
		try {
			serviceResult.setResult(model.update${assign_EntityName}(${camelName}));
		} catch (BusinessException e) {
			serviceResult.setSuccess(false);
			serviceResult.setMessage(e.getMessage());
			log.error("[${content.items.service.className}][update${assign_EntityName}]更新${tableName}表时出现异常：" + e.getMessage());
        } catch (Exception e) {
			serviceResult.setError(ConstantsEJS.SERVICE_RESULT_CODE_SYSERROR, "服务异常，请联系系统管理员。");
			log.error("[${content.items.service.className}][update${assign_EntityName}]更新${tableName}表时出现异常：", e);
		}
			return serviceResult;
    }

	//删除${tableRemark}
	@Override
	public ServiceResult<Integer> delete${assign_EntityName}(@RequestParam("id") ${assign_idFieldType} ${assign_idFieldName}) {
		ServiceResult<Integer> serviceResult = new ServiceResult();
		try {
			serviceResult.setResult(model.delete${assign_EntityName}(${assign_idFieldName}));
		} catch (BusinessException e) {
			serviceResult.setSuccess(false);
			serviceResult.setMessage(e.getMessage());
			log.error("[${content.items.service.className}][delete${assign_EntityName}]删除${tableName}表时出现异常：" + e.getMessage());
		} catch (Exception e) {
			serviceResult.setError(ConstantsEJS.SERVICE_RESULT_CODE_SYSERROR, "服务异常，请联系系统管理员。");
			log.error("[${content.items.service.className}][delete${assign_EntityName}]删除${tableName}表时出现异常：", e);
		}
			return serviceResult;
    }
</#if>

}
